home *** CD-ROM | disk | FTP | other *** search
/ Tech Arsenal 1 / Tech Arsenal (Arsenal Computer).ISO / tek-02 / pas_0593.zip / TSTMODEX.PAS < prev    next >
Pascal/Delphi Source File  |  1993-05-30  |  6KB  |  209 lines

  1. {─ Fido Pascal Conference ────────────────────────────────────────────── PASCAL ─
  2. Msg  : 240 of 288
  3. From : Mark Dixon                          3:690/660.14         10 May 93  21:35
  4. To   : Fiasal Juma                         1:221/177.0
  5. Subj : Animation
  6. ────────────────────────────────────────────────────────────────────────────────
  7. On May 06 05:06, Fiasal Juma of 1:221/177 wrote:
  8.  
  9.  FJ>         Actually, I've experimented with that also.. A
  10.  FJ> simple code like        this for switching pages,
  11.  
  12.  FJ> Procedure Pageswitch(X: Byte);
  13.  
  14.  FJ>     Begin
  15.  FJ>       Asm
  16.  FJ>         mov ah,5
  17.  FJ>         mov al,x
  18.  FJ>         int 10h
  19.  FJ>       end;
  20.  FJ>   end;
  21.  
  22.  
  23.  FJ>         Does not exactly work without a problem in Mode
  24.  FJ> 13h.. I don't        know if you know a better way of
  25.  FJ> switching pages, or even the        right way if I am doing
  26.  FJ> wrong. But I will give what you said        a try.. Thanx
  27.  FJ> for the reply.. Later
  28.  
  29. Well, what you've done above isn't really fast anyway, even though its
  30. assembler, your using interrupts, and that is about as slow as using an XT when 
  31. doing graphics :-)
  32.  
  33. Um, have a gander at this, and see what you can come up with. It's some code I
  34. wrote a while back to use mode-x and do double buffering (or page-flipping).
  35.  
  36. _ _ _ O / _ _ C_U_T_ H_E_R_E_ _ _ _
  37.       O \                          }
  38.  
  39. Program Test_ModeX;
  40.  
  41. Uses crt;
  42.  
  43.  
  44. { This program will put the VGA card into a MODEX mode (still only 320x200)
  45.   and demonstrate double buffering (page flipping)
  46.  
  47.  
  48.   This program was written by Mark Dixon, and has been donated to the
  49.   Public Domain with the exception that if you make use of these routines,
  50.   the author of these routines would appreciate his name mentioned somewhere
  51.   in the documentation.
  52.  
  53.   Use these routines at your own risk! Because they use the VGA's registers,
  54.   cards that are not 100% register compatible may not function correctly, and
  55.   may even be damaged. The author will bear no responsability for any actions
  56.   occuring as a direct (or even indirect) result of the use of this program.
  57.  
  58.   Any donations (eg Money, Postcards, death threats.. ) can be sent to  :
  59.  
  60.   Mark Dixon
  61.   12 Finchley St
  62.   Lynwood,
  63.   Western Australia
  64.   6147
  65.  
  66.   If you have Netmail access, then I can also be contacted on 3:690/660.14
  67.  
  68.   }
  69.  
  70.  
  71. Const
  72.   Page : Byte = 0;
  73.  
  74. Var
  75.   I, J : Word;
  76.  
  77.  
  78. Procedure InitModeX;
  79.  
  80. { Sets up video mode to Mode X (320x200x256 with NO CHAIN4) making available
  81.   4 pages of 4x16k bitmaps }
  82.  
  83. Begin
  84.   asm
  85.     mov    ax, 0013h    { Use bios to enter standard Mode 13h }
  86.     int    10h
  87.     mov    dx, 03c4h    { Set up DX to one of the VGA registers }
  88.     mov    al, 04h      { Register = Sequencer : Memory Modes }
  89.     out    dx, al
  90.     inc    dx           { Now get the status of the register }
  91.     in     al, dx       { from the next port }
  92.     and    al, 0c7h     { AND it with 11000111b ie, bits 3,4,5 wiped }
  93.     or     al, 04h      { Turn on bit 2 (00000100b) }
  94.     out    dx, al       { and send it out to the register }
  95.     mov    dx, 03c4h    { Again, get ready to activate a register }
  96.     mov    al, 02h      { Register = Map Mask }
  97.     out    dx, al
  98.     inc    dx
  99.     mov    al, 0fh      { Send 00001111b to Map Mask register }
  100.     out    dx, al       { Setting all planes active }
  101.     mov    ax, 0a000h   { VGA memory segment is 0a000h }
  102.     mov    es, ax       { load it into ES }
  103.     sub    di, di       { clear DI }
  104.     mov    ax, di       { clear AX }
  105.     mov    cx, 8000h    { set entire 64k memory area (all 4 pages) }
  106.     repnz  stosw        { to colour BLACK (ie, Clear screens) }
  107.     mov    dx, 03d4h    { User another VGA register }
  108.     mov    al, 14h      { Register = Underline Location }
  109.     out    dx, al
  110.     inc    dx           { Read status of register }
  111.     in     al, dx       { into AL }
  112.     and    al, 0bFh     { AND AL with 10111111b }
  113.     out    dx, al       { and send it to the register }
  114.                         { to deactivate Double Word mode addressing }
  115.     dec    dx           { Okay, this time we want another register,}
  116.     mov    al, 17h      { Register = CRTC : Mode Control }
  117.     out    dx, al
  118.     inc    dx
  119.     in     al, dx       { Get status of this register }
  120.     or     al, 40h      { and Turn the 6th bit ON }
  121.     out    dx, al       { to turn WORD mode off }
  122.                         { And thats all there is too it!}
  123.   End;
  124. End;
  125.  
  126.  
  127. Procedure Flip;
  128.  
  129. { This routine will flip to the next page, and change the value in
  130.   PAGE such that we will allways be drawing to the invisible page. }
  131.  
  132. Var
  133.   OfsAdr : Word;
  134. Begin
  135.   OfsAdr := Page * 16000;
  136.   asm
  137.     mov    dx, 03D4h
  138.     mov    al, 0Dh      { Set the Start address LOW register }
  139.     out    dx, al
  140.     inc    dx
  141.  
  142.     mov    ax, OfsAdr
  143.     out    dx, al       { by sending low byte of offset address }
  144.     dec    dx
  145.     mov    al, 0Ch      { now set the Start Address HIGH register }
  146.     out    dx, al
  147.     inc    dx
  148.     mov    al, ah
  149.     out    dx, al       { by sending high byte of offset address }
  150.   End;
  151.  
  152.   Page := 1 - Page;     { Flip the page value.
  153.                           Effectively does a :
  154.                           If Page = 0 then Page = 1 else
  155.                           If Page = 1 then Page = 0.       }
  156. End;
  157.  
  158.  
  159.  
  160. Procedure PutPixel (X, Y : Integer; Colour:Byte );
  161.  
  162. { Puts a pixel on the screen at the current page. }
  163.  
  164. Var
  165.   OfsAdr : Word;
  166. BEGIN
  167.   OfsAdr := Page * 16000;
  168.   ASM
  169.     mov    bx, x
  170.     mov    ax, Y
  171.     mov    cx, 80     { Since there are now 4 pixels per byte, we
  172.                         only multiply by 80 (320/4) }
  173.     mul    cx
  174.     mov    di, ax
  175.     mov    ax, bx
  176.     shr    ax, 1
  177.     shr    ax, 1
  178.     add    di, ax
  179.     and    bx, 3
  180.     mov    ah, 1
  181.     mov    cl, bl
  182.     shl    ah, cl
  183.  
  184.     mov    al, 2
  185.     mov    dx, 03C4h
  186.  
  187.     mov    bx, $A000
  188.     mov    es, bx
  189.     add    di, OfsAdr
  190.  
  191.     out    dx, ax        { Set plane to address (where AH=Plane) }
  192.     mov    al, Colour
  193.     mov    es:[di], al
  194.   end;
  195. end;
  196.  
  197. Begin
  198.   Randomize;
  199.   InitModeX;
  200.   Flip;
  201.   For I := 0 to 319 do
  202.     For J := 0 to 199 do  PutPixel(I, J, Random(32) );
  203.   Flip;
  204.   For I := 0 to 319 do
  205.     For J := 0 to 199 do  PutPixel(I, J, Random(32) +32);
  206.   Repeat
  207.     Flip;
  208.   Until Keypressed;
  209. End.